package service.impl;

import dao.BaseGoodsDao;
import entity.*;
import service.BaseGoodsService;

import java.sql.SQLException;
import java.util.List;

/**
 * Created by Administrator on 2017/11/14.
 */
public class BaseGoodsServiceImpl implements BaseGoodsService {
    private BaseGoodsDao bgd=new BaseGoodsDao();
    @Override
    public List<BaseGoodsEntity> query() {
        List<BaseGoodsEntity> list=null;
        try {
            list=bgd.query();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }finally{
            try {
                bgd.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    @Override
    public List<BaseGoodsEntity> queryNew()  {
       List<BaseGoodsEntity> list=null;
        try {
            list=bgd.queryNew();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            try {
                bgd.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    @Override
    public DetailEntity queryDetails(long goodsid)  {
       DetailEntity de=null;
        try {
            de=bgd.queryDetail(goodsid);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            try {
                bgd.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return de;
    }

    @Override
    public List<AreaEntity> queryArea() {
        List<AreaEntity> list=null;
        try {
            list=bgd.queryShop();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            try {
                bgd.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    @Override
    public int register(String userAccount,String passWord) throws SQLException {
        int r=0;
        try {
            r=bgd.insert(userAccount,passWord);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            bgd.close();
        }
        return r;
    }

    @Override
    public UserEntity login(String userAccount, String userPwd) {
        UserEntity ue=null;
        try {
            ue=bgd.queryAccount(userAccount,userPwd);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            try {
                bgd.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return ue;
    }

    @Override
    public List<GoodsEntity> queryAll()  {
        List<GoodsEntity> list=null;
        try {
            list=bgd.queryAll();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                bgd.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    @Override
    public GoodsEntity queryById(long goodsId) {
        GoodsEntity ge=null;
        try {
            ge=bgd.queryById(goodsId);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            try {
                bgd.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return ge;
    }

    @Override
    public int updateCount(long goodsId, int counts)  {
        int r=0;
        try {
            r=bgd.updateCount(goodsId,counts);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                bgd.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return r;
    }

    @Override
    public GoodsEntity queryCount(long goodsId)  {
        GoodsEntity list=null;
        try {
            list=bgd.queryCount(goodsId);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                bgd.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return list;
    }


}
